package com.base.helper;

import java.util.Date;

/**
 * 准考证号工具类
 * @Author mzl.
 */
public class TicketNumUtils {

    /**
     * 生成准考证号：考试日期年（4）+ 0 +批次编号（1）+ 专业编号（1） + 报考顺序（4）
     * @param examtime
     * @param enrollcode
     * @param subjectcode
     * @param joinNum
     * @return
     */
    public static String getTicketnum(Date examtime, String enrollcode, String subjectcode, Integer joinNum){
        StringBuilder ticketNum=new StringBuilder(DateUtils.date(examtime,"yyyy"));
        ticketNum.append("0");
        ticketNum.append(enrollcode);
        ticketNum.append(subjectcode);
        ticketNum.append(fillIn(joinNum.toString(),4));
        return ticketNum.toString();
    }

    /**
     * 补位
     *
     * @param data
     * @param num
     * @return
     */
    public static String fillIn(String data, Integer num) {
        StringBuilder sb = new StringBuilder();
        if (null == data) {
            data = "";
        }
        for (int i = 0; i < (num - data.length()); i++) {
            sb.append('0');
        }
        sb.append(data);
        return sb.toString();
    }

}
